Skip to content

Conversation

@fdcastel
Copy link

This PR applies the four recommendations outlined by Claude after reviewing the ODBC Crusher report referenced in #153.


ODBC Conformance Improvements

This PR addresses 4 low-severity ODBC conformance issues identified by ODBC Crusher v0.4.5 testing against psqlodbc v16.00.0000, as documented in docs/postgresql_ODBC_RECOMMENDATIONS.md.

Changes

1. Implement SQL_ATTR_CURSOR_SCROLLABLE setter (Level 2)

  • pgapi30.c: Changed SQL_ATTR_CURSOR_SCROLLABLE from unconditionally rejected to a functional setter
  • Maps SQL_SCROLLABLESQL_CURSOR_STATIC, SQL_NONSCROLLABLESQL_CURSOR_FORWARD_ONLY
  • Improves compatibility with ODBC 3.x frameworks that prefer this attribute over SQL_ATTR_CURSOR_TYPE

2. Properly reject unsupported async execution

  • options.c: Return SQL_ERROR (SQLSTATE HYC00) when SQL_ASYNC_ENABLE_ON is requested
  • Previously returned SQL_SUCCESS while silently ignoring the setting, violating the principle of least surprise
  • SQL_ASYNC_ENABLE_OFF remains a successful no-op

3. Fix SQLSTATE for invalid SQLGetInfo types

  • Added CONN_INVALID_INFO_TYPE (215) error code
  • info.c + environ.c: Return HY096 (invalid information type) instead of HYC00 for unrecognized info types
  • Aligns with ODBC spec requirement distinguishing invalid vs. unimplemented features

4. Fix SQLSTATE for invalid connection attributes

  • environ.c: Added explicit CONN_OPTION_NOT_FOR_THE_DRIVERHY092 mapping
  • Previously fell through to generic HY000; now returns spec-compliant HY092 (invalid attribute/option identifier)

Testing

  • Added 3 regression tests: cursor-scrollable-test, async-enable-test, odbc-conformance-test
  • All tests pass on Windows with PostgreSQL 17

Impact

Low-severity spec compliance improvements. No breaking changes. The driver already supported all underlying functionality; these changes improve error reporting and API surface consistency with the ODBC 3.x specification.

Implement SQL_ATTR_CURSOR_SCROLLABLE as a writable attribute in
PGAPI_SetStmtAttr. Setting SQL_SCROLLABLE maps to SQL_CURSOR_STATIC,
and SQL_NONSCROLLABLE maps to SQL_CURSOR_FORWARD_ONLY.

Previously the driver unconditionally rejected this attribute with
SQL_ERROR, even though it fully supports scrollable cursors via
SQL_ATTR_CURSOR_TYPE.

Add cursor-scrollable regression test to verify the behavior.
Return SQL_ERROR with SQLSTATE HYC00 when an application attempts to
enable asynchronous execution, which the driver does not support.
Previously the driver silently ignored the request, returning
SQL_SUCCESS, which misled applications into believing async was active.

Setting SQL_ASYNC_ENABLE_OFF remains a successful no-op.

Add async-enable regression test to verify the behavior.
Rec 3: Return SQLSTATE HY096 for invalid SQLGetInfo info types instead
of HYC00. Add CONN_INVALID_INFO_TYPE error code (215) mapped to HY096.
Use it in PGAPI_GetInfo for unrecognized info type values.

Rec 4: Return SQLSTATE HY092 for invalid SQLSetConnectAttr attributes
instead of HY000. Add explicit SQLSTATE mapping for the existing
CONN_OPTION_NOT_FOR_THE_DRIVER error code to HY092. Previously this
code had no mapping and fell through to the generic HY000 default.
Add odbc-conformance test that verifies:
- SQLGetInfo with invalid info type returns SQLSTATE HY096
- SQLSetConnectAttr with invalid attribute returns SQLSTATE HY092

Also register all new tests (async-enable, cursor-scrollable,
odbc-conformance) in the test/tests list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant